package com.atguigu.userprofile.dao;

import com.atguigu.userprofile.bean.TaskTagRule;
import com.atguigu.userprofile.util.MySqlUtil;

import java.util.List;

/**
 * 负责TaskTagRule的增删改查
 */
public class TaskTagRuleDao {

    public static void main(String[] args) {

        List<TaskTagRule> taskTagRules = selectTaskTagRulesByTaskId("1");
        System.out.println(taskTagRules.size());
        taskTagRules.forEach(System.out::println);
    }

    /**
     * 通过任务id查询TaskTagRule
     */
    public static List<TaskTagRule> selectTaskTagRulesByTaskId( String taskId ){

        String querySql = "SELECT \n" +
                "ttr.id ,ttr.tag_id , ttr.task_id , ttr.query_value , ttr.sub_tag_id , ti.tag_name AS sub_tag_value\n" +
                "FROM\n" +
                "task_tag_rule ttr JOIN tag_info ti\n" +
                "ON ttr.sub_tag_id = ti.id\n" +
                "WHERE ttr.task_id = " + taskId ;

        List<TaskTagRule> taskTagRules = MySqlUtil.selectList(querySql, TaskTagRule.class, true);

        return taskTagRules ;
    }
}
